home *** CD-ROM | disk | FTP | other *** search
- #include "PStringStuff.h"
-
- // various Pascal string manipulation utilities since we're not using C strings.
-
- // CopyPString copies the first string to the second (snarfed from TBUtilities.c
- // from Symantec)
-
- // ConcatPStrings concatenates the second string onto the end of the first
- // (snarfed from TBUtilities.c from Symantec).
-
- // int2Str converts an int into a string, correctly handling negative numbers.
-
- // PsubStr takes a string, a start position, and an end position and returns
- // the string piece. Note that this is destructive; if you need to preserve the
- // original, call the routine on a copy of the string.
-
- // Pstrcmp does NOT work like its C equivalent. It returns TRUE if they
- // are the same, and FALSE if they are not. The C equivalent returns 0 (FALSE)
- // if they are the same, -1 if string 2 < string 1, and 1 if string 2 > string1.
-
- // stripColons assumes you pass it something like a pathname, and want the part
- // AFTER the last colon. Note that it is destructive of the string you pass it.
-
-
- void CopyPString(ConstStr255Param srcString, Str255 destString)
- {
- BlockMove(srcString, destString, srcString[0] + 1L);
- }
-
-
- void Pcharcat(Str255 srcString, char addThis)
- {
- if (srcString[0] < 255)
- {
- srcString[0] += 1;
- srcString[srcString[0]] = addThis;
- }
- }
-
-
- void ConcatPStrings(Str255 first, ConstStr255Param second)
- {
-
- short charsToCopy;
-
- // Truncate if concatenated string would be longer than 255 chars.
-
- charsToCopy = Min(second[0], 255 - first[0]);
- BlockMove(second + 1, first + first[0] + 1, (long) charsToCopy);
- first[0] += charsToCopy;
- }
-
- void int2Str(short theNum, Str255 theString)
- {
- NumToString((long)Abs(theNum),theString);
-
- if (theNum < 0)
- {
- Str255 swapStr; // we need a temporary swap string
-
- CopyPString("\p-",swapStr);
- ConcatPStrings(swapStr,theString);
- CopyPString(swapStr,theString);
- }
- }
-
- void PsubStr(unsigned char *dest, short startPos, short endPos)
-
- {
- short i;
- Str255 tempStr;
-
- if (startPos < 1) // startPos must be greater than zero
- startPos = 1;
- if (endPos > dest[0]) // endPos must be a valid part of the string
- endPos = dest[0];
- else if (endPos < startPos) // endPos must be at least startPos
- endPos = startPos;
-
- tempStr[0] = endPos - startPos +1; // example…5-3+1 = 3 chars (#s 3,4 & 5)
- for (i = startPos; i <= endPos; i++)
- {
- tempStr[i-startPos+1] = dest[i];
- }
- CopyPString(tempStr,dest);
- }
-
- Boolean Pstrcmp(unsigned char *string1, unsigned char *string2)
- {
- short i;
-
- if (*string1 != *string2)
- return FALSE;
-
- for (i = 0; i <= *string1; i++)
- {
- if (string1[i] != string2[i])
- return FALSE;
- }
- return TRUE;
- }
-
- void stripColons(Str255 theString)
- {
- short i;
- short j = theString[0];
-
- if (theString[0] != 0)
- {
-
- for (i=theString[0];i>0;i--)
- {
- if (theString[i] == ':')
- break;
- if (theString[i] == '\r')
- j = i;
- }
-
- if (i != 0)
- {
- PsubStr(theString,i+1,j);
- }
- }
- }
-
- int findString(Str255 strToFind, Str255 strToSearch)
- {
- // returns the position of strToFind in strToSearch
-
- short i,j;
-
- for(i=1; i <= strToSearch[0]-strToFind[0]; i++)
- {
- j=0;
- while((strToFind[j+1] == strToSearch[i+j]) && (j < strToFind[0]))
- j++;
-
- if (j == strToFind[0])
- return i;
- }
- return 0;
-
- }
-